package com.thinksns.sociax.t4.model;

import com.thinksns.sociax.thinksnsbase.bean.SociaxItem;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 类说明：用于发现界面
 * Created by zycx on 2016/12/7.
 */

public class ModelFind extends SociaxItem {
    private List<ModelAds> banner; // 广告
    private List<FindListviewModel> weibas; // 微吧
    private List<FindListviewModel> topics; // 话题
    private List<FindListviewModel> channels; // 频道
    private List<FindListviewModel> information; // 资讯
    private List<FindListviewModel> users; // 找人
    private List<FindListviewModel> near_users; // 附近的人
    private List<FindListviewModel> gifts; // 积分商城
    private List<FindListviewModel> lives; //
    private List<FindListviewModel> jipu_goods; //极铺商城

    private List<List<FindListviewModel>> allModules;

    public ModelFind() {
    }

    public ModelFind(JSONObject object) {
        try {
            FindListviewModel findListviewModel;
            if (object.has("banner")) {
                banner = new ArrayList<>();
                JSONArray bannerArr = object.optJSONArray("banner");
                for (int i = 0; i < bannerArr.length(); i++) {
                    banner.add(new ModelAds(bannerArr.optJSONObject(i)));
                }
            }
            if (object.has("weibas")) {
                weibas = new ArrayList<>();
                JSONArray weibasArr = object.optJSONArray("weibas");
                for (int i = 0; i < weibasArr.length(); i++) {
                    ModelWeiba w = new ModelWeiba(weibasArr.optJSONObject(i));
                    String url = w.getAvatar_middle();
                    int id = w.getWeiba_id();
                    String bottom = w.getWeiba_name();
                    findListviewModel = new FindListviewModel(url, "", bottom, id, 1);
                    weibas.add(findListviewModel);
                }
            }
            if (object.has("topics")) {
                topics = new ArrayList<>();
                JSONArray topicsArr = object.optJSONArray("topics");
                for (int i = 0; i < topicsArr.length(); i++) {
                    JSONObject j = topicsArr.optJSONObject(i);
                    String url = j.optString("pic");
                    int id = j.optInt("topic_id");
                    String center = j.optString("topic_name");
                    findListviewModel = new FindListviewModel(url, center, "", id, 0);
                    topics.add(findListviewModel);
                }
            }
            if (object.has("channels")) {
                channels = new ArrayList<>();
                JSONArray channelsArr = object.optJSONArray("channels");
                for (int i = 0; i < channelsArr.length(); i++) {
                    JSONObject j = channelsArr.optJSONObject(i);
                    String url = j.optString("pic");
                    int id = j.optInt("channel_category_id");
                    String center = j.optString("title");
                    findListviewModel = new FindListviewModel(url, center, "", id, 0);
                    channels.add(findListviewModel);
                }
            }

            if (object.has("information")) {
                information = new ArrayList<>();
                JSONArray informationArr = object.optJSONArray("information");
                for (int i = 0; i < informationArr.length(); i++) {
                    JSONObject j = informationArr.optJSONObject(i);
                    String url = j.optString("pic");
                    int id = j.optInt("id");
                    String bottom = j.optString("subject");
                    String detail_url = j.optString("url");
                    findListviewModel = new FindListviewModel(url, "", bottom, id, 1);
                    findListviewModel.setUrl(detail_url);
                    information.add(findListviewModel);
                }
            }
            if (object.has("users")) {
                users = new ArrayList<>();
                JSONArray usersArr = object.optJSONArray("users");
                for (int i = 0; i < usersArr.length(); i++) {
                    JSONObject j = usersArr.optJSONObject(i);
                    String url = j.optString("avatar");
                    int id = j.optInt("uid");
                    String bottom = j.optString("uname");
                    int space_privacy = j.optInt("space_privacy");
                    findListviewModel = new FindListviewModel(url, "", bottom, id, 1);
                    findListviewModel.setSpace_privacy(space_privacy);
                    users.add(findListviewModel);
                }
            }
            if (object.has("near_users")) {
                near_users = new ArrayList<>();
                JSONArray near_usersArr = object.optJSONArray("near_users");
                for (int i = 0; i < near_usersArr.length(); i++) {
                    JSONObject j = near_usersArr.optJSONObject(i);
                    String url = j.optString("avatar");
                    int id = j.optInt("uid");
                    String bottom = j.optString("uname");
                    int space_privacy = j.optInt("space_privacy");
                    findListviewModel = new FindListviewModel(url, "", bottom, id, 1);
                    findListviewModel.setSpace_privacy(space_privacy);
                    near_users.add(findListviewModel);
                }
            }
            if (object.has("gifts")) {
                gifts = new ArrayList<>();
                JSONArray giftsArr = object.optJSONArray("gifts");
                for (int i = 0; i < giftsArr.length(); i++) {
                    JSONObject j = giftsArr.optJSONObject(i);
                    String url = j.optString("image");
                    int id = j.optInt("id");
                    String center = j.optString("name");
                    findListviewModel = new FindListviewModel(url, center, "", id, 0);
                    gifts.add(findListviewModel);
                }
            }
            if (object.has("jipu_goods")) {
                jipu_goods = new ArrayList<>();
                JSONArray jipuGoods = object.optJSONArray("jipu_goods");
                for (int i = 0; i < jipuGoods.length(); i++) {
                    JSONObject j = jipuGoods.optJSONObject(i);
                    String url = j.optString("cover_path");
                    int id = j.optInt("id");
                    String center = j.optString("name");
                    findListviewModel = new FindListviewModel(url, center, "", id, 0);
                    jipu_goods.add(findListviewModel);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            allModules = new ArrayList<>();
            allModules.add(weibas);
            allModules.add(topics);
            allModules.add(channels);
            allModules.add(information);
            allModules.add(users);
            allModules.add(near_users);
            allModules.add(gifts);
            allModules.add(jipu_goods);
        }
    }

    @Override
    public boolean checkValid() {
        return false;
    }

    @Override
    public String getUserface() {
        return null;
    }

    public List<ModelAds> getBanner() {
        return banner;
    }

    public void setBanner(List<ModelAds> banner) {
        this.banner = banner;
    }

    public List<FindListviewModel> getWeibas() {
        return weibas;
    }

    public void setWeibas(List<FindListviewModel> weibas) {
        this.weibas = weibas;
    }

    public List<FindListviewModel> getTopics() {
        return topics;
    }

    public void setTopics(List<FindListviewModel> topics) {
        this.topics = topics;
    }

    public List<FindListviewModel> getChannels() {
        return channels;
    }

    public void setChannels(List<FindListviewModel> channels) {
        this.channels = channels;
    }

    public List<FindListviewModel> getInformation() {
        return information;
    }

    public void setInformation(List<FindListviewModel> information) {
        this.information = information;
    }

    public List<FindListviewModel> getUsers() {
        return users;
    }

    public void setUsers(List<FindListviewModel> users) {
        this.users = users;
    }

    public List<FindListviewModel> getNear_users() {
        return near_users;
    }

    public void setNear_users(List<FindListviewModel> near_users) {
        this.near_users = near_users;
    }

    public List<FindListviewModel> getGifts() {
        return gifts;
    }

    public void setGifts(List<FindListviewModel> gifts) {
        this.gifts = gifts;
    }

    public List<FindListviewModel> getLives() {
        return lives;
    }

    public void setLives(List<FindListviewModel> lives) {
        this.lives = lives;
    }

    public List<FindListviewModel> getJipu_goods() {
        return jipu_goods;
    }

    public void setJipu_goods(List<FindListviewModel> jipu_goods) {
        this.jipu_goods = jipu_goods;
    }

    public List<List<FindListviewModel>> getAllModules() {
        return allModules;
    }

    public void setAllModules(List<List<FindListviewModel>> allModules) {
        this.allModules = allModules;
    }
}
